Skip to main content

All Questions

0votes
2answers
72views

Trying to figure out the best and worst case time complexity of a function. Is it possibly that worst and best case are the same?

I've been asked to find the best and worst case time complexity "in terms of their running time as a function of input size, n." I'm pretty new to Big O but I was doing okay will the other ...
Mia Good's user avatar
1vote
1answer
85views

Is this algorithm with three nested loops O(m*n) or O(m*n^2)?

i'm doing a code challenge for funzies and trying to determine the time complexity of my solution. it's been a minute since college so i want to confirm i'm doing this analysis correctly. here's the ...
Turner J's user avatar
1vote
1answer
205views

Populate the Diagonal Elements of An Array MATLAB

I have the following matrix C that I would like to recreate in MATLAB: In this case uppercase C is an N = 3 by N = 3 matrix, but I would like to generate C for any size of N by N. I randomly create ...
Jonathan Frutschy's user avatar
2votes
1answer
96views

Populate A Function Handle "Array" in MATLAB

I have the following function handle uppercase K and array of lowercase k and gamma values. N = 3; k = randi([1,1000],N+1,1,"double"); gamma = randi([1,100],N+1,1,"double"); K = @...
Jonathan Frutschy's user avatar
1vote
1answer
79views

Running time of 3 nested for-loops, where the innermost loop depends on the operations in the outer loop (not an obvious case)

I'm a beginner here studying algorithms for the first time. I'd like to know the running time of the following algorithm with 3 nested for loops. I know in most cases it's the lengths of the loops ...
CodingPup's user avatar
-1votes
2answers
577views

Optimizing a Nested Loop Algorithm for Maximum Efficiency

I'm working on a project that involves processing a large dataset with nested loops, and I'm struggling to optimize my code for maximum efficiency. Here's my current approach, which I know is not ...
prabu naresh's user avatar
-1votes
2answers
76views

Optimizing Python Code for Finding Index Pairs Meeting Specific Inequality

I have a Python code that efficiently solves my task, but I'm concerned about its time complexity. The task is to find the number of index pairs (i, j) where the inequality aᵢ ⊕ aʲ ≥ bᵢ ⊕ bʲ holds ...
Maxviz's user avatar
0votes
1answer
55views

Big O notation of nested loops

function compressBoxesTwice(box1, box2) { box1.forEach(function (boxes) { console.log(box1); box2.forEach(function (boxes) { console.log(box2); }) }) } compressBoxesTwice(); ...
Hamza Baig's user avatar
0votes
1answer
112views

generating a nth prime number without using 'isprime()' function

there is no output for the code when the input exceeds two. import java.util.Scanner; class PrimeNumberFinder { static boolean is_prime(int number ,int[] prime_numbers) { boolean is_prime =...
Pranshu's user avatar
-2votes
1answer
72views

What is the big O of a nested loop when the inner loop is of variale length?

What is the time complexity of this? The outer loop is O(log n). But I am not sure about the inner loop? Is it O(log n) also? Would that make this entire algorithm O(n log n)? while (n > 0) { ...
Zuse's user avatar
  • 103
0votes
2answers
179views

How to make Python to run 4 nested loops faster?

I have 4 nested loops in my Python code and it takes ages to finish all the loops when the grids are big. For example, here is a piece of my code: from itertools import product T = 50 beta ...
Zuba Tupaki's user avatar
2votes
1answer
717views

How do I write a python function to maximize sum of N X N upper left sub-matrix from given 2N X 2N matrix?

I have this problem to solve: Given a 2N x 2N matrix of integers, you are allowed to reverse any row or column any number of times and in any order. The task is to calculate the maximum sum of the ...
micahondiwa's user avatar
0votes
1answer
168views

How to make the code runs faster in Python (multiple nested for loops efficiency)

I have some codes here that I want to know if there's a way to make the code run better and take less time... I use multiple nested loops here and I don't really know how to improve this piece of code,...
EintsWaveX's user avatar
-1votes
1answer
51views

How to take out or change Key name of array-like object?

I need to calculate the average scores per sub-array in javascript .. To do that i'm aiming to do a double loop for array[i][j].. but the problem is the key name or index per each sub-array is above ...
Momo's user avatar
0votes
2answers
396views

Use nested C loops to produce the following out put

Am a beginner in C and I came across this question, How to produce the following pattern using C nested loops BBBBBBB BBBBBB BBBBB BBBB BBB BB Code # include <stdio.h> int main() { int Row, ...
Eric paul's user avatar

153050per page
close